// (
//    function (){
//        //1.创建私有变量和私有方法
//        let privateVariable = 10;
//        function privateFunction(){
//            console.log('---privateFunction--');
//        }
//        //2.创建定义在全局作用域上的构造函数
//        MyObject = function(){};
//        //3.在构造函数的原型上创建特权方法
//        MyObject.prototype.publicMethod = function(){
//            return {
//                privateVariable,
//                privateFunction
//            }
//        }
//    }
// )()
// let object = new MyObject();
// console.log(MyObject.prototype.publicMethod());
// //{ privateVariable: 10, privateFunction: [Function: privateFunction] }
// console.log(object.publicMethod());
// //{ privateVariable: 10, privateFunction: [Function: privateFunction] }
//
(
    function (){
        //1.定义私有变量
        let name="";
        //2.定义暴露在全局作用域的构造函数
        Person = function(value){
            name = value
        };
        //3.定义在构造函数原型
        Person.prototype.getName = function(){
            return name;
        }
        Person.prototype.setName = function (value){
            name = value;
        }
    }
)()
let person1 = new Person('Smith');
console.log(person1.getName())//Smith
person1.setName('Alice');
console.log(person1.getName())//Alice
let person2 = new Person('Tom');
console.log(person1.getName());//Tom
console.log(person2.getName());//Tom